package com.intct.func;

import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.digest.DigestUtil;
import org.apache.flink.table.functions.ScalarFunction;

import java.sql.Timestamp;

/**
 * @author gufg
 * @since 2025-10-21 16:36
 */
public class RowKeyFunction extends ScalarFunction {
    public static String eval(String value, int numRegion) {

        // 获取value的hash -> 取绝对值 -> 取余
        int hashValue = Math.abs(value.hashCode()) % numRegion;

        // md5  --> substring 12
        String md5Str = DigestUtil.md5Hex(value).substring(0, 12);

        return hashValue + md5Str;
    }

    public static String eval(Timestamp value) {
        long time = DateUtil.parse(String.valueOf(value)).getTime();
        return String.valueOf(time);
    }

}
